package study02;

import java.util.Calendar;

public class Java14_Date_test {
    public static void main(String[] args) {
//        打印当前日历
        System.out.println("周一\t周二\t周三\t周四\t周五\t周六\t周日\t");
        Calendar firstDay = Calendar.getInstance();
//        把日历对象设置当前月的第一天
        firstDay.set(Calendar.DAY_OF_MONTH, 1);
//        获取当前月的最大日期
        int maxDay = firstDay.getMaximum(Calendar.DAY_OF_MONTH);
        for (int i = 0; i < maxDay; i++) {
            // 当前是周几
            int weekX = firstDay.get(Calendar.DAY_OF_WEEK);
            // 当前是几号
            int monthY = firstDay.get(Calendar.DAY_OF_MONTH);
            if (i == 0 ) {
                if ( weekX == Calendar.SUNDAY ) {
                    for (int j = 0; j < 6; j++) {
                        System.out.print("\t");
                    }
                    System.out.println(monthY);
                } else {
//                    看前面有几个空格
                    for (int j = 0; j < weekX - 2; j++) {
                        System.out.print("\t");
                    }
                    System.out.print(monthY);
                    System.out.print("\t");
                }
            } else {
//                不是一号的情况
                if ( weekX == Calendar.SUNDAY ) {
                    System.out.println(monthY);
                } else {
                    System.out.print(monthY);
                    System.out.print("\t");
                }
            }
//          打印增加一天
            firstDay.add(Calendar.DATE, 1);
        }
    }
}
